#! /bin/bash

set -eo pipefail
shopt -s nullglob

cd $project_path
#modify the django config file settings.py
#sed  -i  's/127.0.0.1/10.10.205.90/;s/mySql12#4,.De/cmdbcmdb/;s/117.33.233.74/10.10.205.90/' $project_path/cmdb/settings.py
sed  -i  "s/127.0.0.1/$mysql_address/;s/mySql12#4,.De/$mysql_pwd/;s/117.33.233.74/$es_address/" $project_path/cmdb/settings.py

#generate the uwsgi.ini
cat > $project_path/uwsgi.ini << EOF
[uwsgi]
chdir=$project_path
module=cmdb.wsgi:application
master=True
pidfile=./project-master.pid
vacuum=True
max-requests=500
#daemonize=./uwsgi.log
socket=$socket_address
#http = :8000
processes = 1
threads = 2
buffer-size=32768
EOF

python3 manage.py migrate 
echo yes | python3 manage.py collectstatic
python3 tools/setup/create_superuser.py
uwsgi --ini uwsgi.ini
exec "$@"
